package com.cloud.sky.entity.common;


import lombok.Data;


/**
 * 通用响应结果
 *
 * @author Tyrone
 * @date 2024/7/14 17:16
 */
@Data
public class Result<T> {

    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String msg;

    private T data;

    public Result() {

    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();

    }

    public static <T> Result<T> success(T data) {
        return new Result(ResultCode.success, data);
    }

    public static Result failure(ResultCode resultCode) {
        return new Result(resultCode);
    }

    public static Result failure(String msg) {
        return new Result(ResultCode.failure.getCode(), msg);
    }
}
